package store;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Iterator;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.*;
import org.apache.hadoop.io.compress.CompressionCodec;
import org.apache.hadoop.io.compress.GzipCodec;
import org.apache.hadoop.mapred.RecordWriter;
import org.apache.hadoop.mapred.Reporter;
import org.apache.hadoop.mapreduce.Job;

import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.apache.hadoop.util.Progressable;
import org.apache.hadoop.util.ReflectionUtils;

import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;
/*
public class XMLFileOutFormat extends FileOutputFormat<Text, Text> {
	public RecordWriter<Text, Text> getRecordWriter(TaskAttemptContext job)
			throws IOException, InterruptedException {
		Configuration conf = job.getConfiguration();
		boolean isCompressed = getCompressOutput(job);
		String keyValueSeparator = conf.get(
				"mapred.textoutputformat.separator", "\t");
		CompressionCodec codec = null;
		String extension = "";
		if (isCompressed) {
			Class<? extends CompressionCodec> codecClass = getOutputCompressorClass(
					job, GzipCodec.class);
			codec = (CompressionCodec) ReflectionUtils.newInstance(codecClass,
					conf);
			extension = codec.getDefaultExtension();
		}
		Path file = getDefaultWorkFile(job, extension);
		FileSystem fs = file.getFileSystem(conf);
		if (!isCompressed) {
			FSDataOutputStream fileOut = fs.create(file, false);
			return new LineRecordWriter<Text, Text>(fileOut, keyValueSeparator);
		} else {
			FSDataOutputStream fileOut = fs.create(file, false);
			return new LineRecordWriter<Text, Text>(new DataOutputStream(codec
					.createOutputStream(fileOut)), keyValueSeparator);
		}
	}

	protected static class XMLWritableRecordWriter implements
			RecordWriter<Text, Text> {

		private static final String utf8 = "UTF-8";
		private static final byte[] newline;
		private static final byte[] keyValueSeparator;
		private static final byte[] colon;
		private static final byte[] comma;
		static {
			try {
				newline = "\n".getBytes(utf8);
				keyValueSeparator = "\t".getBytes(utf8);
				colon = ":".getBytes(utf8);
				comma = ",".getBytes(utf8);
			} catch (UnsupportedEncodingException uee) {
				throw new IllegalArgumentException("can't find " + utf8
						+ " encoding");
			}
		}

		protected DataOutputStream out;

		public XMLWritableRecordWriter(DataOutputStream out) {
			this.out = out;
		}

		@Override
		public synchronized void write(Text key, Text value) throws IOException {
			out.write(key.getBytes(), 0, key.getLength());
			out.write(keyValueSeparator);

			// Iterator<Writable> it = value.iterator();
			// while (it.hasNext()) {
			// Writable k = it.next();
			// LongWritable v = (LongWritable) value.get(k);

			out.write(key.getBytes());
			out.write(colon);
			out.write(value.getBytes());
			out.write(comma);
			// }

			out.write(newline);
		}

		@Override
		public synchronized void close(Reporter reporter) throws IOException {
			out.close();
		}

	}
}*/
